package com.ruoyi.weixin.shop.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.weixin.shop.domain.vo.WxHomeLayoutAddBo;
import com.ruoyi.weixin.shop.domain.vo.WxHomeLayoutEditBo;
import com.ruoyi.weixin.shop.domain.vo.WxHomeLayoutQueryBo;
import com.ruoyi.weixin.shop.domain.vo.WxHomeLayoutVo;
import com.ruoyi.weixin.shop.service.IWxHomeLayoutService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商城首页分类Controller
 *
 * @author ruoyi
 * @date 2021-07-15
 */
@Api(value = "商城首页分类控制器", tags = {"商城首页分类管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/shop/homelayout")
public class WxHomeLayoutController extends BaseController {

	private final IWxHomeLayoutService iWxHomeLayoutService;

	/**
	 * 查询商城首页分类列表
	 */
	@ApiOperation("查询商城首页分类列表")
	@PreAuthorize("@ss.hasPermi('shop:homelayout:list')")
	@GetMapping("/list")
	public AjaxResult<List<WxHomeLayoutVo>> list(@Validated WxHomeLayoutQueryBo bo) {
		List<WxHomeLayoutVo> list = iWxHomeLayoutService.queryList(bo);
		return AjaxResult.success(list);
	}

	/**
	 * 导出商城首页分类列表
	 */
	@ApiOperation("导出商城首页分类列表")
	@PreAuthorize("@ss.hasPermi('system:layout:export')")
	@GetMapping("/export")
	public AjaxResult<WxHomeLayoutVo> export(@Validated WxHomeLayoutQueryBo bo) {
		List<WxHomeLayoutVo> list = iWxHomeLayoutService.queryList(bo);
		ExcelUtil<WxHomeLayoutVo> util = new ExcelUtil<WxHomeLayoutVo>(WxHomeLayoutVo.class);
		return util.exportExcel(list, "商城首页分类");
	}

	/**
	 * 获取商城首页分类详细信息
	 */
	@ApiOperation("获取商城首页分类详细信息")
	@PreAuthorize("@ss.hasPermi('system:layout:query')")
	@GetMapping("/{id}")
	public AjaxResult<WxHomeLayoutVo> getInfo(@NotNull(message = "主键不能为空")
											  @PathVariable("id") Long id) {
		return AjaxResult.success(iWxHomeLayoutService.queryById(id));
	}

	/**
	 * 新增商城首页分类
	 */
	@ApiOperation("新增商城首页分类")
	@PreAuthorize("@ss.hasPermi('system:layout:add')")
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody WxHomeLayoutAddBo bo) {
		return toAjax(iWxHomeLayoutService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改商城首页分类
	 */
	@ApiOperation("修改商城首页分类")
	@PreAuthorize("@ss.hasPermi('system:layout:edit')")
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody WxHomeLayoutEditBo bo) {
		return toAjax(iWxHomeLayoutService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除商城首页分类
	 */
	@ApiOperation("删除商城首页分类")
	@PreAuthorize("@ss.hasPermi('system:layout:remove')")
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iWxHomeLayoutService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
